package com.fs.controller;

import com.fs.pojo.UserAddr;
import com.fs.service.DistrictService;
import com.fs.service.UserAddrService;
import com.fs.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api("地址管理")
@RestController
@RequestMapping("/addr")
public class AddressController extends BaseController {
    @Autowired
    private DistrictService districtService;

    @Autowired
    private UserAddrService userAddrService;

    @ApiOperation("根据父级id，获取子级列表")
    @GetMapping("/district/{addrId}")
    public ResultVO getDistrict(@PathVariable("addrId") String addrId){
        return districtService.getDistrict(addrId);
    }

    @ApiOperation("添加-编辑地址")
    @PostMapping("/add")
    public ResultVO addAddr(@RequestBody UserAddr userAddr){
        return userAddrService.addAddr(userAddr,getUserId());
    }

    @ApiOperation("地址列表")
    @PostMapping("/list")
    public ResultVO addrList(){
        return userAddrService.addrList(getUserId());
    }

    @ApiOperation("删除地址")
    @DeleteMapping("/del")
    public ResultVO addrDel(Integer id){
        return userAddrService.addrDel(id,getUserId());
    }
}
